/*
 * board_init.c
 *
 *  Created on: 2012-01-25
 *      Author: byron
 */

#include "config.h"
#include "LPC177x_8x.h"
#include "lcd_cortex.h"

#define PINSEL(x,y) (x) &= 0x07; \
	(x) |= (y)


volatile unsigned int GDIM_X = 320;
volatile unsigned int GDIM_Y = 240;

extern unsigned int TypPCB;
extern unsigned int TypPCB_TLM;

static unsigned long icer0,icer1;

void irq_all_disable()
{
	icer0 = NVIC->ICER[0];
	icer1 = NVIC->ICER[1];

	/* Disable all interrupts */
	NVIC->ICER[0] = 0xFFFFFFFF;
	NVIC->ICER[1] = 0x00000001;
	/* Clear all pending interrupts */
	NVIC->ICPR[0] = 0xFFFFFFFF;
	NVIC->ICPR[1] = 0x00000001;
}

void irq_all_enable()
{
	NVIC->ICER[0] = icer0;
	NVIC->ICER[1] = icer1;
}

#define LCDRST_OFF 	LPC_GPIO0->PIN |= (1<<17)
#define LCDRST_ON 	LPC_GPIO0->PIN &= ~(1<<17)

#define BUZZER_ON 	LPC_GPIO0->PIN |= (1<<6)
//FIO0SET = (1<<6)	// BUZZER ON
#define BUZZER_OFF LPC_GPIO0->PIN &= ~(1<<6)

void GpioInit(void)
{
	LPC_GPIO4->DIR |=(1<<15);// DE1
	LPC_GPIO4->PIN &= ~(1<<15);

	LPC_GPIO1->DIR |=(1<<3); //LAMP

	LPC_GPIO2->DIR |=(1<<0); //LCDPWR

	LPC_GPIO0->DIR |=(1<<17); //RSTLCD
	LCDRST_OFF;

	LPC_GPIO0->DIR |=(1<<6); //BUZZER

	LPC_GPIO1->DIR |=(1<<2); //BUZZER TLM P1.2
	LPC_GPIO1->PIN |= (1<<2);     //BUZZER_TLM(OFF)

	LPC_GPIO1->DIR |=(1<<7); //PWM LCD TLM P1.7
	LPC_GPIO1->PIN &= ~(1<<7); //PWM LCD (MAX)

	BUZZER_OFF;

}

void ea1788_mem_if(void);

void EMC_init()
{
	//ea1788_mem_if();
}





int BoardSpecificInit()
{
	GpioInit();
}
